
/*--------------------------------------------------------------------------
  
  Use the event command 'Execute Script / Execute Code' to change the message layout to the specified ID.
  The ID of the new message layout is saved in the save file.
  
  Usage:
  
  To dynamically change the message layout, write as follows.
  
  changeMessageLayout(MessageLayout.TEROP, 5);
  
  To return the message layout to the default, write as follows.
  
  changeMessageLayout(MessageLayout.TEROP, -1);
  
  Author:
  SapphireSoft
  https://srpgstudio.com/
  
  History:
  2023/03/11 Released
  
--------------------------------------------------------------------------*/

function changeMessageLayout(type, id) {
	if (type === MessageLayout.TOP) {
		if (id === -1) {
			delete root.getMetaSession().global.layout_top;
		}
		else {
			root.getMetaSession().global.layout_top = id;
		}
	}
	else if (type === MessageLayout.CENTER) {
		if (id === -1) {
			delete root.getMetaSession().global.layout_center;
		}
		else {
			root.getMetaSession().global.layout_center = id;
		}
	}
	else if (type === MessageLayout.BOTTOM) {
		if (id === -1) {
			delete root.getMetaSession().global.layout_bottom;
		}
		else {
			root.getMetaSession().global.layout_bottom = id;
		}
	}
	else if (type === MessageLayout.TEROP) {
		if (id === -1) {
			delete root.getMetaSession().global.layout_terop;
		}
		else {
			root.getMetaSession().global.layout_terop = id;
		}
	}
	else if (type === MessageLayout.STILL) {
		if (id === -1) {
			delete root.getMetaSession().global.layout_still;
		}
		else {
			root.getMetaSession().global.layout_still = id;
		}
	}
};

(function() {

var alias1 = MessageShowEventCommand._getLayoutTop;
MessageShowEventCommand._getLayoutTop = function() {
	if (typeof root.getMetaSession().global.layout_top !== 'undefined') {
		return getLayout(root.getMetaSession().global.layout_top);
	}
	else {
		return alias1.call(this);
	}
};

var alias2 = MessageShowEventCommand._getLayoutCenter;
MessageShowEventCommand._getLayoutCenter = function() {
	if (typeof root.getMetaSession().global.layout_center !== 'undefined') {
		return getLayout(root.getMetaSession().global.layout_center);
	}
	else {
		return alias2.call(this);
	}
};

var alias3 = MessageShowEventCommand._getLayoutBottom;
MessageShowEventCommand._getLayoutBottom = function() {
	if (typeof root.getMetaSession().global.layout_bottom !== 'undefined') {
		return getLayout(root.getMetaSession().global.layout_bottom);
	}
	else {
		return alias3.call(this);
	}
};

var alias4 = MessageTeropEventCommand._getMessageLayout;
MessageTeropEventCommand._getMessageLayout = function() {
	if (typeof root.getMetaSession().global.layout_terop !== 'undefined') {
		return getLayout(root.getMetaSession().global.layout_terop);
	}
	else {
		return alias4.call(this);
	}
};

var alias5 = StillMessageEventCommand._getMessageLayout;
StillMessageEventCommand._getMessageLayout = function() {
	if (typeof root.getMetaSession().global.layout_still !== 'undefined') {
		return getLayout(root.getMetaSession().global.layout_still);
	}
	else {
		return alias5.call(this);
	}
};

function getLayout(id) {
	return root.getBaseData().getMessageLayoutList().getDataFromId(id);
};

})();
